<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //创建表格元素
    var tb=document.createElement("table");
    tb.setAttribute("border",1);
    tb.setAttribute("height","280px");
    tb.setAttribute("width","500px");
    tb.setAttribute("cellspacing",0);
    //创建行
    for(var i=0;i<7;i++){
        var trObj=document.createElement("tr");
        for(var j=0;j<5;j++){
            var tdObj=document.createElement("td");
            if(j==0){
                tdObj.style.width="120px";
                var btn=document.createElement("button");
                btn.innerHTML="点击我删除第"+i+"行";
                btn.onclick=function(){//在多次循环中，btn里存的值可能不是你期望的，所以不要出现btn，用this
                   // btn.parentNode.removeChild(btn);
                   tb.removeChild(this.parentNode.parentNode);

                }
                tdObj.appendChild(btn);
            }
            trObj.appendChild(tdObj);
        }
        tb.appendChild(trObj);
    }
    document.body.appendChild(tb);
</script>
</html>